package org.codefinger.dao.impl.sql;

import org.codefinger.dao.impl.Querier;
import org.codefinger.dao.impl.SQLVisitor;
import org.codefinger.dao.util.Lang;

public class SubQuerySource implements Source {

	private Querier	querier;

	private String	suffix;

	public SubQuerySource(Querier querier, String alias) {
		super();
		this.querier = querier;
		this.suffix = Lang.joinStr(alias.length() + 2, ") ", alias);
	}

	@Override
	public void visit(SQLVisitor visitor) {
		visitor.appendSQL(" FROM (");
		querier.visitAsQuery(visitor);
		visitor.appendSQL(suffix);
	}

}
